package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.entity.Goods;
import com.serkol.ams.entity.TaocanDetail;
import com.serkol.ams.mapper.TaocanDetailMapper;
import com.serkol.ams.modal.SqlFeildModal;
import com.serkol.ams.service.GoodsService;
import com.serkol.ams.service.TaocanDetailService;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author pingan
* @description 针对表【taocan_detail】的数据库操作Service实现
* @createDate 2023-10-22 14:33:33
*/
@Service
public class TaocanDetailServiceImpl extends ServiceImpl<TaocanDetailMapper, TaocanDetail>
    implements TaocanDetailService{
    @Autowired
private GoodsService goodsService;
    @Override
    public List<Map<String,Object>> findGoodsList(long taocanId, long agentId) {
        MyLambdaQueryWrapper<Goods> queryWrapper=new MyLambdaQueryWrapper<>();
        queryWrapper.select(SqlFeildModal.getGoodsTaoCanNewListFeild(taocanId,agentId));

        return goodsService.listMaps(queryWrapper);
    }

    @Override
    public List<Map<String, Object>> findByDetailList(long taocanId) {
        Map<String, Object> param=new HashMap<>();
        param.put("ID","GOODS_ID");
        MyLambdaQueryWrapper<TaocanDetail> queryWrapper=new MyLambdaQueryWrapper<>();
        queryWrapper.select(TaocanDetail::getQuantity)
                .select(TaocanDetail::getGoodsId).as("goodsId")
                .select(TaocanDetail::getPaymentAmount).as("paymentAmount")
                .select(TaocanDetail::getPrice).as("price")
                .select(TaocanDetail::getDiscountAmount).as("discountAmount")
                .select(TaocanDetail::getTotalAmount).as("totalAmount")
                .select(SqlFeildModal.getPictureKey("(SELECT IMAGE_ID FROM goods where ID=x.GOODS_ID LIMIT 1)")).as("image")
                .otherTableColmuns("goods","NAME",param).as("name");
        queryWrapper.eq(TaocanDetail::getTaocanId,taocanId).gt(TaocanDetail::getQuantity,0);

        return this.listMaps(queryWrapper);
    }
}




